<div class="list-body">
	<form id="proto-search-form" data-toggle="ajaxform" data-options="{beforeSubmit:setProtoSearchValue,url: '/protocoldictionary/list',validate: false,okalert:false,loadingmask: true,okCallback:getProtoListData}">
		<div class="row">
			<div class="search-input">
	        	<input type="text"  id="proto-name-input" placeholder="输入传感器名称" autocomplete="off" onblur="Trim(this,this.value)">
	        	<input type="hidden" name="name" id="protocoldictionaryNameDisNone" >
				<div style="display: none;">
	                    <input type="text" name="pageCurrent" value="1">
	                    <input type="text" name="pageSize" value="12">
	                </div>
	        	  <button type="submit"  class="search-btn" data-icon="search"></button>
	    	</div>
	    	<a class="add-btn" onclick="dialog_protocoldictionary_add()"><i class="fa fa-plus-square-o"></i><span>添加私有协议字典</span></a>
		</div>
	
    </form>
    <ul class="row proto-list-content list-content">

	</ul>
	<div id="pagination_proto" style="text-align: center;  display: none;"></div>

</div>

<script type="text/javascript">
$(function(){
    var protocoldictionaryTotalNum;
    pagination_callback(1, 12,1);
	$("input").placeholder();

})

function setProtoSearchValue(from){
	$('#proto-name-input').val()!='输入传感器名称' ? $('#protocoldictionaryNameDisNone').val($('#proto-name-input').val()) : $('#protocoldictionaryNameDisNone').val('');
	return true;
}
function getProtoListData(json, options){
	$('#pagination_proto').pagination('destroy')     //删？
	$('#pagination_proto').pagination({
   	 	total:json.totalRow, pageSize:12, callback:pagination_callback
	})
	protocoldictionaryTotalNum=json.totalRow;
   set_list(json);
    if(json.totalRow<=12){
      $("#pagination_proto").css("display","none");
    }else{
      $("#pagination_proto").css("display","block");
  	}
}
function pagination_callback(pageCurrent, pageSize,num) {
		var name=$("#protocoldictionaryNameDisNone").val(); // //取出存进的参数值

	   BJUI.ajax('doajax', {
          	url: '/protocoldictionary/list',
          	okalert:false,
          	type:'post',
	        data: {pageCurrent:pageCurrent, pageSize:pageSize,name:name},
	        okCallback: function(json, options) {
	            set_list(json);
	             if(num==1){
                     $('#pagination_proto').pagination({
                    total:json.totalRow, pageSize:12, callback:pagination_callback
                }) 
                  }
                 protocoldictionaryTotalNum=json.totalRow;
                  if(json.totalRow>pageSize){
                    $("#pagination_proto").css("display","block");
                  }else{
                  	$("#pagination_proto").css("display","none");
                  }
	        }
	    })
	}


	function set_list(json){
		$('.proto-list-content').empty();
	    var btnArr=[
	        {title:"编辑",icon:"fa fa-edit",fun:"protocoldictionary_edit"},
	        {title:"详情",icon:"fa fa-list-alt",fun:"protocoldictionary_detail"},
	        {title:"删除",icon:"fa fa-trash-o",fun:"protocoldictionary_del"},
	     ];
		$('.proto-list-content').setList(json.list,btnArr,'fa-book');
	
	}

function dialog_protocoldictionary_add(){
	BJUI.dialog({
		id:"appAdd",
		url:"/protocoldictionary/editPage",
		title:"添加私有协议字典",
        type:"post",
		width:"620",
		height:"600",
		mask:true,
		maxable:false
	})
}

function protocoldictionary_edit(obj){
        var id=$(obj).parent().parent().prevAll("#item-id").text();
        BJUI.dialog({
             id:"appEdit",
             url:"/protocoldictionary/editPage",
             title:"编辑私有协议字典",
             type:"post",
             data:{"id":id},
             width:"620",
             height:"600",
             mask:true,
             maxable:false
            }) 
       }
       
function protocoldictionary_del(obj){
		var id=$(obj).parent().parent().prevAll("#item-id").text();
		BJUI.alertmsg('confirm', '确定要删除吗！', {
            okCall: function() { //点击确定时运行
		     BJUI.ajax('doajax',{
		           url:"/protocoldictionary/del",
		           type:"post",
		           loadingmask: true,
		           dataType:"json",
		           data: {'id':id},
		           okCallback: function(json, options) {
		           	 protocoldictionaryTotalNum -=1;
                $('#pagination_proto').pagination('destroy')
                $('#pagination_proto').pagination({
            total:protocoldictionaryTotalNum, pageSize:12, callback:pagination_callback
        });
                       pagination_callback(1,12,1);
                    }
		       })
              }
            })
		    
		}

function protocoldictionary_detail(obj){  //查看私有协议字典详情
        var id=$(obj).parent().parent().prevAll("#item-id").text();
        
            BJUI.dialog({
                 id:"protocoldictionaryEdit",
                 url:"/protocoldictionary/detail",
                 title:"私有协议字典",
                 type:"post",
                 data:{"id":id},
                 width:"620",
                 height:"600",
                 mask:true,
                 maxable:false
           }) 
         
    }

</script>

